﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Network;

public class GameMono : MonoBehaviour {
    private static GameMono m_instance;

    public static GameMono Instance
    {
        get {
            if (m_instance == null)
            {
                GameObject g = new GameObject();
                g.name = "GameMono";
                m_instance = g.AddComponent<GameMono>();
            }
            return m_instance; 
        }
    }
    private List<object> servlist = new List<object>();
    public T GetServer<T>() where T : class
    {
        for (int i = 0; i < servlist.Count; i++)
        {
            object o = servlist[i];
            if (typeof(T) == o.GetType())
            {
                return (T)o;
            }
        }
        return null;
    }

    public void Init()
    {

    }

    void Awake()
    {
//         servlist.Add(new DirServer());
//         servlist.Add(new BussicnessServer());

        servlist.Add(NetEngine.Instance);

        for (int i = 0; i < servlist.Count; i++)
        {
            IInitializeable o = (IInitializeable)servlist[i];
            o.Initialize();
        }
    }

	// Use this for initialization
	void Start () {
	}
	
	// Update is called once per frame
	void Update () 
    {
        for (int i = 0; i < servlist.Count; i++)
        {
            IUpdateable o = (IUpdateable)servlist[i];
            o.Update();
        }
	}
}
